package com.ibuonline.b2b.search.dao;

import com.dimeng.common.base.SuperDAO;
import com.ibuonline.b2b.entity.SearchWord;

import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Component;

/**
 *
 * @author daojindi-yf
 */
@Component
public class SearchWordDAO extends SuperDAO<SearchWord> {

    @SuppressWarnings("unchecked")
    public List<Object[]> queryBySqlAndPaging(final String sql, final int startRow, final int size) {
        return template.executeFind(new HibernateCallback() {

            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query query = session.createSQLQuery(sql);
                query.setFirstResult(startRow);
                query.setMaxResults(size);
                return query.list();
            }
        });
    }

    public int getRecordCountBySQL(String sql) {
        return jdbcTemplate.queryForInt(sql);
    }
}
